from thrift.transport import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol

from hbase import Hbase
from hbase.ttypes import *

def create_client(transport):
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    transport.open()
    return Hbase.Client(protocol)

def close_trans(transport):
    transport.close()

def get_one_data(client):
    result = client.getRow('emp2', 'row-key1')
    for r in result:
        print('the row is ', r.row)
        print('the values of personal:name is ', r.columns.get('personal:name').value)
        print('the values of personal:city is ', r.columns.get('personal:city').value)
        print('the values of professional:designation is ', r.columns.get('professional:designation').value)
        print('the values of professional:salary is ', r.columns.get('professional:salary').value)


if __name__ == '__main__':
    socket = TSocket.TSocket('master', 9090)
    transport = TBufferedTransport(socket)
    client = create_client(transport)
    get_one_data(client)
    close_trans(transport)